package per.turtle.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import per.turtle.common.core.annotation.MaxSizeWithCharset;
import per.turtle.common.core.constant.UserConstants;
import per.turtle.common.core.web.entity.BaseEntity;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author turtle
 */
@ApiModel(value = "SysUser", description = "用户")
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@TableName("sys_user")
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("用户ID")
    @TableId(type = IdType.ASSIGN_UUID)
    private String userId;

    @ApiModelProperty("部门ID")
    private String deptId;

    @TableField(exist = false)
    private String deptName;

    @ApiModelProperty("用户账号")
    @NotBlank(message = "用户账号不能为空")
    @MaxSizeWithCharset(max = 31, message = "用户账号超出限定长度！")
    private String userName;

    @ApiModelProperty("用户昵称")
    @MaxSizeWithCharset(max = 31, message = "用户名称超出限定长度！")
    private String nickName;

    @ApiModelProperty("用户邮箱")
    @Email(message = "邮箱格式不正确")
    @MaxSizeWithCharset(max = 63, message = "邮箱长度超出限定长度！")
    private String email;

    @ApiModelProperty("手机号码")
    @MaxSizeWithCharset(max = 11, message = "手机号码超出限定长度！")
    private String phoneNumber;

    @ApiModelProperty("用户性别")
    private Integer sex;

    @ApiModelProperty("用户头像")
    private String avatar;

    @ApiModelProperty("密码")
    private String password;

    /**
     * todo 尚未使用
     */
    @ApiModelProperty("盐加密")
    @TableField(exist = false)
    private String salt;

    @ApiModelProperty("是否停用（1：是；0：否）")
    private Boolean isDisabled;

    @ApiModelProperty("部门对象")
    private SysDept dept;

    @ApiModelProperty("角色对象")
    private List<SysRole> roles;

    @ApiModelProperty("角色组")
    private List<String> roleIds;

    @ApiModelProperty("岗位组")
    private List<String> postIds;

    @ApiModelProperty("备注")
    private String remark;

    public SysUser(String userId) {
        this.userId = userId;
    }

    public static boolean isAdmin(String userId) {
        return UserConstants.ADMIN_USER_ID.equals(userId);
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

}
